#!/usr/bin/env python3
"""
Main entry point for the Three.js to GIF converter.
This module handles configuration loading and initiates the GIF generation process.
"""

import logging
from pathlib import Path
from utils import setup_logging, get_project_root, resolve_path, load_config
from renderer import generate_gif

def main():
    """Main function to orchestrate the GIF generation process."""
    setup_logging()
    
    try:
        # Load configuration
        config_path = get_project_root() / "config" / "settings.json"
        config = load_config(config_path)
        
        # Resolve paths
        config['html_file'] = str(resolve_path(config['html_file']))
        config['output_gif'] = str(resolve_path(config['output_gif']))
        
        # Ensure output directory exists
        output_dir = Path(config['output_gif']).parent
        output_dir.mkdir(parents=True, exist_ok=True)
        
        # Generate GIF
        generate_gif(
            html_file=config['html_file'],
            output_gif=config['output_gif'],
            frames=config['frames'],
            resolution=config['resolution'],
            frame_delay=config['frame_delay'],
            config=config
        )
        
        logging.info("GIF generation completed successfully!")
        
    except Exception as e:
        logging.error(f"Error during execution: {e}")
        raise

if __name__ == "__main__":
    main()